<?php

require_once dirname(__FILE__) . '/Config.php';
require_once dirname(__FILE__) . '/Models/Record.php';
/**
 * Rank all page retrieve from Google
 * @author HungNQ
 */
$record = new Record;

$numPrevDay = 1;
$today = strtotime("today 00:00");
$yesterday = strtotime("-$numPrevDay day", $today);

$day = date('d', $yesterday);
$month = date('m', $yesterday);
$year = date('Y', $yesterday);

$results = $record->getRecords($day, $month, $year);

$rank = 0;
$update_query = array();
foreach ($results as $row) {
    $rank++;
    //echo $row['page_views'] . "\n";
    $update_query[] = $record->buildRankingQuery($row['id'], $rank);
}

$updateRank = $record->updateRank($update_query);